package swim.sessionbeans;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.jboss.ejb3.annotation.RemoteBinding;

@Stateless
@RemoteBinding(jndiBinding="LoginRemote")
public class Login implements LoginRemote{

	@PersistenceContext(unitName = "swim")
	private EntityManager manager;
	
	@Override
	public Long loginUtente(String user, String password) {
		Query q = manager.createQuery("SELECT id FROM Utente WHERE email_login='"+user+"' AND password='"+password+"'");
		if(q.getResultList().size()==1){
			return (Long) q.getSingleResult();
		}else{
			return -1L;
		}
		
	}

	

}
